<?php
/**
* kit class for simpletest kit
* @author J.Ducastel <jeremie@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

class SimpleTestKit extends Webappkit {

	/**
	* call this method to run kit tests
	* 
	*/
	function run() {
		// has groups ?
		//$groups=&$this->getGroups();
		//echo '<pre>'; print_r($groups);
		if ($this->getGroupTools()) {
			if ($group=$_GET['group']) {
				$this->runToolsGroup($group);
			} else {
				// producing nav
				$this->ToolsMenu();
			}
		} else {
			$this->runAllTestClasses();
		}
	}
	
	function runAllTestClasses($label='All test classes') {
		$group=new GroupTest($label);
		// searching for all declared test classes
		$classes=get_declared_classes();
		foreach ($classes as $class) {
			if (strtolower(substr($class,0,4))!='test')
				continue;
			// adding class to group test
			$group->addTestClass($class);
		}
		// running group test
		$group->run(new HtmlReporter());
		print_r($group);
	}
	
	/**
	 * return group tools
	 */
	function getGroupTools() {
		return $this->getTools('simpletestgrouptool');
	}
	
	/**
	 * produces a page with groups menu
	 */
	function ToolsMenu() {
		// print_r($this->getGroups());
		echo '<dl>';
		foreach ($this->getGroupTools() as $name => $group) {
			// print_r($group);
			$cfg=$group->getCfg();
			// $name=$group->name;
			echo '<dt><a href="?group='.$name.'">'.$name.'</a></dt>'
			.'<dd>'.$cfg['group']['desc'].'</dd>';
		}
		echo '</dl>';
	}
	
	function runToolsGroup($name) {
		$this->$name->runTests();
	}
}
?>